﻿using System;
using System.CodeDom.Compiler;
using System.Collections.Generic;
using System.ComponentModel;
using System.Diagnostics;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Markup;
using VerticalMenu.Utility;

namespace VerticalMenu.Controls
{
	public partial class LeftTabControl : UserControl
	{
		public LeftTabControl()
		{
			this.InitializeComponent();
			this.constHeight = base.Height;
		}

		public event RoutedEventHandler ClickTitle;

		public event RoutedEventHandler ClickItem;

		private int TITLE_COUNT
		{
			get
			{
				return this.m_CommandTableInfos.TableInofList.Count;
			}
		}

		public CommandTableInfos CmndTableInfos
		{
			set
			{
				this.m_CommandTableInfos = value;
			}
		}

		public bool Initialize()
		{
			bool flag = this.m_CommandTableInfos != null;
			bool result;
			if (flag)
			{
				bool flag2 = this.TITLE_COUNT > 0;
				if (flag2)
				{
					for (int i = 0; i < this.TITLE_COUNT; i++)
					{
						SinglePanel singlePanel = new SinglePanel();
						singlePanel.TabInofs = this.m_CommandTableInfos.TableInofList[i];
						singlePanel.ID = i;
						singlePanel.controlWidth = this.stackPanel.Width;
						singlePanel.controlHeight = 0.0;
						singlePanel.ClickItem += this.mltc_ClickItem;
						singlePanel.ClickTitle += this.mltc_ClickTitle;
						singlePanel.HorizontalAlignment = HorizontalAlignment.Stretch;
						this.stackPanel.Children.Add(singlePanel);
						this.singlePanelList.Add(singlePanel);
					}
					this.SetConstHeight(this.constHeight);
					this.singlePanelList[0].controlHeight = this.constHeight - this.BUTTON_HEIGHT * (double)this.TITLE_COUNT;
					this.SizeChange();
					result = true;
				}
				else
				{
					result = false;
				}
			}
			else
			{
				result = false;
			}
			return result;
		}

		public void AutomaticallyFixToScreenHeight(double height)
		{
			bool flag = height - this.BUTTON_HEIGHT * (double)this.TITLE_COUNT > 0.0;
			if (flag)
			{
				this.singlePanelList[this.currentTabID].controlHeight = height - this.BUTTON_HEIGHT * (double)(this.TITLE_COUNT - this.currentTabID);
				base.Height = height;
			}
		}

		private void mltc_ClickItem(object sender, RoutedEventArgs e)
		{
			bool flag = this.ClickItem != null;
			if (flag)
			{
				this.ClickItem(sender, e);
			}
		}

		private void mltc_ClickTitle(object sender, RoutedEventArgs e)
		{
			SinglePanel singlePanel = (SinglePanel)sender;
			bool flag = singlePanel.ID != this.currentTabID;
			if (flag)
			{
				singlePanel.controlHeight = this.constHeight - this.BUTTON_HEIGHT * (double)this.TITLE_COUNT;
				this.singlePanelList[this.currentTabID].controlHeight = 0.0;
				this.currentTabID = singlePanel.ID;
			}
			bool flag2 = this.ClickTitle != null;
			if (flag2)
			{
				this.ClickTitle(sender, e);
			}
		}

		private void UserControl_SizeChanged(object sender, SizeChangedEventArgs e)
		{
			this.SizeChange();
			this.singlePanelList[this.currentTabID].controlHeight = 0.0;
			this.singlePanelList[this.currentTabID].controlHeight = this.constHeight - this.BUTTON_HEIGHT * (double)this.TITLE_COUNT;
		}

		private void SizeChange()
		{
			this.SetConstHeight(base.ActualHeight);
			this.stackPanel.Width = base.ActualWidth;
			foreach (object obj in this.stackPanel.Children)
			{
				SinglePanel singlePanel = (SinglePanel)obj;
				singlePanel.Width = this.stackPanel.Width;
			}
		}

		private void SetConstHeight(double value)
		{
			double num = this.BUTTON_HEIGHT * 2.0;
			double num2 = this.BUTTON_HEIGHT * (double)this.TITLE_COUNT + num;
			bool flag = Common.LessThan(value, num2, 0.1);
			if (flag)
			{
				value = num2;
			}
			this.constHeight = value;
		}

		private List<SinglePanel> singlePanelList = new List<SinglePanel>();

		private double BUTTON_HEIGHT = 23.0;

		private int currentTabID = 0;

		private double constHeight = 0.0;

		private CommandTableInfos m_CommandTableInfos;
	}
}
